package com.sky.chapter3.lockSupport;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author : wushikai
 * <p>
 * date : 2022-07-05
 * 之前错误的先唤醒后等待，LockSupport照样支持
 */
class LockSupportDemo7 {
    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(3);  //先卡住
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "\t" + System.currentTimeMillis());
            LockSupport.park();  //第二部执行 卡住
            System.out.println(Thread.currentThread().getName() + "\t" + System.currentTimeMillis() + "---被叫醒");
        }, "t1");
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        LockSupport.unpark(t1);  // 第一步执行 唤醒
        System.out.println(Thread.currentThread().getName() + "\t" + System.currentTimeMillis() + "---unpark over");
    }
}

